﻿@using Frogsoft.Permission.Dtos
@implements IDialogContentComponent<AppUserDto>
@rendermode InteractiveServer
@inject Frogsoft.Permission.UserService UserService
@attribute [Authorize(Policy = "system_permission_user")]

<FluentGrid Spacing="3">
    <FluentGridItem xs="12" sm="6">
        <FluentTextField @bind-Value="Content.UserName" Disabled="true" Label="用户名" Style="width: 100%" />
    </FluentGridItem>
    <FluentGridItem xs="12" sm="6">
        <FluentTextField @bind-Value="Content.FullName" Disabled="true" Label="姓名" Style="width: 100%" />
    </FluentGridItem>
    <FluentGridItem xs="12" sm="6">
        <FluentTextField @bind-Value="Content.Email" Label="邮箱" Style="width: 100%" />
    </FluentGridItem>
    <FluentGridItem xs="12" sm="6">
        <FluentTextField @bind-Value="Content.Mobile" Label="手机号" Style="width: 100%" />
    </FluentGridItem>

</FluentGrid>

<FluentDialogFooter>
    <FluentButton Appearance="Appearance.Accent" @onclick="SaveChanges">保存</FluentButton>
    <FluentButton @onclick="CloseDialog">取消</FluentButton>
</FluentDialogFooter>

@code {
    [Parameter]
    public AppUserDto Content { get; set; } = default!;

    [CascadingParameter]
    public FluentDialog? Dialog { get; set; }

    private async Task SaveChanges()
    {
        try
        {
            UserService.Update(Content);
            await CloseDialog();
        }
        catch (Exception ex)
        {
            // 这里可以添加错误处理，比如显示错误消息
            Console.WriteLine($"Error updating user: {ex.Message}");
        }
    }

    private Task CloseDialog()
    {
        return Dialog?.CloseAsync();
    }
}
